<template>
    <div class="tab-control">
        <!--仅仅是文字不同时，不需要设置slot-->
        <div v-for="(item,index) in titles"
             class="tab-control-item"
             :class="{'tab-control-item-active':index===currentItemIndex}"
             @click="handleClick(index)">
            <span>{{item}}</span>
        </div>
    </div>
</template>
<script>
export default {
    name: 'TabControl',
    props: {
        titles: {
            type: Array,
            default: function () {
                return [];
            }
        }
    },
    data: function () {
        return {
            currentItemIndex: 0
        }
    },
    methods: {
        handleClick: function (index) {
            this.currentItemIndex = index;
            this.$emit('tabClick', index);
        },

    }

}
</script>
<style scoped>
.tab-control {
    display: flex;
    height: 40px;
    position: sticky;
    top: 44px;
    line-height: 40px;
    background-color: #fff;
    text-align: center;
    font-size: 15px;
    z-index: 99;
}

.tab-control-item {
    flex: 1;
}

.tab-control-item > span {
    padding: 5px;
}

.tab-control-item-active {
    color: var(--color-high-text);
}

.tab-control-item-active > span {
    border-bottom: 3px solid var(--color-tint);
}
</style>